package managedBean;

import Merlion.MRP.bean.ProductionManagementBeanRemote;
import Merlion.util.state.PlannedDemandState;
import java.util.ArrayList;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.PhaseEvent;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

@ManagedBean(name = "ProductionExecutionManagedBean")
@ViewScoped
public class ProductionExecutionManagedBean {
    private boolean status = false;
    private List<PlannedDemandState> pds;
   
    @EJB
    private ProductionManagementBeanRemote epmb;

    public ProductionExecutionManagedBean() {
    }

    public void initView(PhaseEvent event) {
        System.out.println("**ProductionExecutionManagedBean : initView()");
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        
        pds = epmb.viewTodayProductionPlan();
        if (pds != null) {
            System.out.println("INIT VIEW : PDS NOT NULL");

        } else {
            System.out.println("INIT VIEW : PDS IS NULL");
        }
              
    }
    
    public void doExecute(ActionEvent event) {
        epmb.executeTodayProductionPlan();
        this.setStatus(true);
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("ProductionExecution.xhtml");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public List<PlannedDemandState> getPds() {
        
        return pds;
    }

    public void setPds(List<PlannedDemandState> pds) {
        this.pds = pds;
    }

    public ProductionManagementBeanRemote getEpmb() {
        return epmb;
    }

    public void setEpmb(ProductionManagementBeanRemote epmb) {
        this.epmb = epmb;
    }
}
